package com.wjq.boot.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sun.org.apache.xpath.internal.operations.Bool;
import com.wjq.boot.entity.Role;
import com.wjq.boot.service.RoleService;
import com.wjq.boot.vo.ResultVo;
import io.minio.errors.*;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.io.IOException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.util.List;

/**
 * <p>
 * 角色表 前端控制器
 * </p>
 *
 * @author wangjiaquan
 * @since 2024-08-07
 */
@RestController
@RequestMapping("/role")
public class RoleController {

    @Resource
    private RoleService roleService;

    @GetMapping("list")
    public ResultVo<IPage<Role>> getPage(Integer pageNo, Integer pageSize){
        return ResultVo.success(roleService.page(new Page<Role>(pageNo,pageSize)),"不弹窗");
    }

    @PostMapping("/fixState")
    public ResultVo<Boolean> fixState(Long id, Boolean state){
        return ResultVo.success(roleService.fixState(id,state),"操作成功");
    }

    @GetMapping("/find")
    public ResultVo<IPage<Role>> getTargetPage(Integer pageNo, Integer pageSize,String keyword){
        return ResultVo.success(roleService.getTargetPage(pageNo,pageSize,keyword),"不弹窗");
    }

    @PostMapping("/add")
    public ResultVo<Boolean> add(String name, String description, MultipartFile file) throws ServerException, InsufficientDataException, ErrorResponseException, IOException, NoSuchAlgorithmException, InvalidKeyException, InvalidResponseException, XmlParserException, InternalException {
        return ResultVo.success(roleService.add(name,description,file),"添加成功");
    }

    @GetMapping("/getById")
    public ResultVo<Role> getById(Long id){
        return ResultVo.success(roleService.list(new QueryWrapper<Role>().eq("id",id)).get(0),"不弹窗");
    }

    @GetMapping("/check")
    public ResultVo<Boolean> check(Long id,String value,String column){
        return ResultVo.success(roleService.check(id,value,column),"不弹窗");
    }

    @PostMapping("/update")
    public ResultVo<Boolean> update(Long id,String name,String description,MultipartFile file,String icno) throws ServerException, InsufficientDataException, ErrorResponseException, IOException, NoSuchAlgorithmException, InvalidKeyException, InvalidResponseException, XmlParserException, InternalException {
        return ResultVo.success(roleService.update(id,name,description,file,icno),null);
    }
}
